package desarrollo;

import java.awt.*;
import java.awt.event.*;
import java.awt.event.KeyEvent;
import javax.swing.JButton;

public class MainFrame {

    public static void main(String[] args) {
        Frame f = new Frame("MainFrame");
        final TextArea ta = new TextArea();
        final TextField tf = new TextField("");
        final JButton b = new JButton("Enviar");
        final JButton b1 = new JButton("Reset");
        MenuBar mb = new MenuBar();
        Menu m = new Menu("Archivo");
        MenuItem mi = new MenuItem("Nuevo");
        MenuItem mi1 = new MenuItem("Salir");
        mb.add(m);
        m.add(mi);
        m.add(mi1);
        Panel p = new Panel();
        Panel p2 = new Panel();
        p.setLayout(new GridLayout(1, 2));
        f.add(BorderLayout.CENTER, ta);
        f.add(BorderLayout.SOUTH, p);
        f.setMenuBar(mb);
        p.add(tf);
        p2.add(b);
        p2.add(b1);
        p.add(p2);
        mi.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                ta.setText("");
                tf.setText("");
            }
        });
        mi1.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                System.exit(0);
            }
        });
        tf.addKeyListener(new KeyAdapter() {

            public void keyPressed(KeyEvent e) {
                if (e.getKeyCode() == 10) {
                    ta.append(tf.getText() + "\n");

                }
            }
        });
        b1.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                ta.setText("");
                tf.setText("");
            }
        });
        b.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                ta.append(tf.getText() + "\n");
            }
        });

        b.addMouseListener(new MouseAdapter() {

            public void mouseEntered(MouseEvent e) {
                b.setBackground(Color.GREEN);
            }

            public void mouseExited(MouseEvent e) {
                b.setBackground(Color.red);
            }
        });
        b1.addMouseListener(new MouseAdapter() {

            public void mouseEntered(MouseEvent e) {
                b.setBackground(Color.GREEN);
            }

            public void mouseExited(MouseEvent e) {
                b.setBackground(Color.red);
            }
        });
        f.addWindowListener(new WindowAdapter() {

            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });

        f.setLocation(400, 200);
        f.setSize(344, 200);
        f.setVisible(true);
    }
}
